home *** CD-ROM | disk | FTP | other *** search
Text File | 1990-01-04 | 26.9 KB | 974 lines | [TEXT/PJMM] |
- Unit TDialogs;
-
- { ⌐1986-1989 Bill Stackhouse }
- { Stackhouse Software }
- { Natick, MA 01760 }
-
- Interface
-
- {$IFC UNDEFINED UsePopUpMenu}
- {$SETC UsePopUpMenu = FALSE}
- {$ENDC}
-
- {$IFC UNDEFINED UseRadioGroup}
- {$SETC UseRadioGroup = FALSE}
- {$ENDC}
-
- {$IFC UNDEFINED UseTextGroup}
- {$SETC UseTextGroup = FALSE}
- {$ENDC}
-
- {$IFC UNDEFINED UseKeyGroup}
- {$SETC UseKeyGroup = FALSE}
- {$ENDC}
-
- {$IFC UNDEFINED UseUserItem}
- {$SETC UseUserItem = FALSE}
- {$ENDC}
-
- {$IFC UNDEFINED UseListItem}
- {$SETC UseListItem = FALSE}
- {$ENDC}
-
- Uses
- TObject,
- {$IFC UsePopUpMenu}
- TPopUpMenu,
- {$ENDC}
- {$IFC UseRadioGroup}
- TRadioGroup,
- {$ENDC}
- {$IFC UseTextGroup}
- TTextGroup,
- {$ENDC}
- {$IFC UseKeyGroup}
- TKeyGroup,
- {$ENDC}
- {$IFC UseUserItem}
- TUserItem,
- {$ENDC}
- {$IFC UseListItem}
- TListItem,
- {$ENDC}
- Centered;
-
- Const
- DialogMaxItems = 255;
- ReturnCode = 13; {ASCII code generated by Return and Enter keys. Note that}
- EnterCode = 3; {this is good for any keyboard, no matter how it's mapped}
-
- { Return Codes }
- DialogNoErr = 0; {all's well with the world}
- DialogNotNumber = -1; {Edit/Static text item did not have a number in it}
- DialogInvalidOp = -2; {Operation requested with support compiled out}
- DialogInvalidItem = -3; {item type invalid for op. eg. GetString on a radio control}
- DialogGroupIgnored = -10; {too many groups, key, menus, or user items were added}
-
- Type
- DialogNumber = 0..DialogMaxItems;
- DialogSet = Packed Set Of DialogNumber;
-
- TDialog = Object(TObject)
- fPrivate: Handle;
-
- { Init - initialize internal data structures }
- { Define - define basic information about dialog }
- { Display - show dialog }
- { Accept - process all event until button is pressed }
- { Error - returns error from last operation }
- { Free - take dialog window down and clean up internal data structures }
- Procedure TDialog.Init;
- Procedure TDialog.Define (pNumber: Integer; {dialog number}
- pChkDefault: DialogSet; {which check bopes default on}
- pTextDefault: DialogNumber); {which editText to put I-Beam}
- Procedure TDialog.Display (center: Boolean);
- Function TDialog.Accept: Integer;
- Function TDialog.Error: Integer;
- Procedure TDialog.Free;
- override;
-
- { RadioGroup - define a group of related radio buttons which are exclusive of each other }
- { RadioGroupGet - find which button in the group is on }
- { RadioGroupSet - set a button in the group }
- Procedure TDialog.RadioGroup (pOn: DialogNumber; {which is initially on}
- pBtns: DialogSet; {which btns in a single group}
- pTitle: String; {if length > 0, then title with box}
- pTitleTop: Boolean); {TRUE - title on top, FALSE - title at left end}
- Procedure TDialog.RadioGroupGet (pGroup: Integer;
- Var pItem: Integer);
- Procedure TDialog.RadioGroupSet (pGroup: Integer;
- pItem: Integer);
-
- { TextGroup - a check box / TextItem pair. When the check is on, the edit is selected}
- Procedure TDialog.TextGroup (pItem: DialogNumber; {pairs of btn and edit text items}
- pText: DialogNumber); {button item number}
-
- { PopMenu - define a popup menu relative to a StaticText item }
- { PopMenuGet - find which menu item is currently on along with its' text }
- { PopMenuCallBack - user call back when popup used. No parms passed back since obj known }
- Procedure TDialog.PopMenu (pMenu: MenuHandle; {nil or menu handle}
- pMenuRes: Integer; {resource number}
- pStatic: DialogNumber; {related StaticText item number}
- pInitiallyOn: Integer); {menu item number initially on}
- Procedure TDialog.PopMenuGet (pGroup: Integer; {group number}
- Var pItem: Integer; {menu item number currently on}
- Var pText: Str255); {menu item text currently on}
- Procedure TDialog.PopMenuCallBack (pCallBack: ProcPtr); {proc addr}
-
- { UserItems - define a user item }
- Procedure TDialog.UserItems (pItem: DialogNumber; {user item number}
- pDraw, pEvent, pSelect: ProcPtr; {draw/event/select call backs}
- pBox: Rect); {Rect that contains the item}
-
- { ItemList - define a single column scrolable list }
- { ItemListText - add a single row to the list }
- { ItemListGet - find which item and its' text was last clicked }
- Procedure TDialog.ItemList (pItem: DialogNumber; {item number}
- pInitiallyOn: Integer; {item initially selected}
- pShown: Integer); {max items to show}
- Procedure TDialog.ItemListText (pText: Str255); {text single list item}
- Procedure TDialog.ItemListGet (pGroup: Integer; {group number}
- Var pItem: Integer; {list item number currently selected}
- Var pText: Str255); {list item text currently selected}
-
- { KeyButton - define keyboard equivalents }
- Procedure TDialog.KeyButton (pKey: char; {command key}
- pItem: DialogNumber); {button}
-
- { General utilities to set and retireve dialog item values }
- Function TDialog.GetBooleanValue (pItem: Integer): Boolean;
- Function TDialog.GetLongintValue (pItem: Integer): Longint;
- Function TDialog.GetStringValue (pItem: Integer): Str255;
-
- Procedure TDialog.SetBooleanValue (pItem: Integer;
- theValue: Boolean);
- Procedure TDialog.SetLongintValue (pItem: Integer;
- theValue: Longint);
- Procedure TDialog.SetStringValue (pItem: Integer;
- theValue: Str255;
- forceFit: Boolean);
-
- { CenterText - center the displayed text in the EditText }
- { SelectText - select the entire text in the EditText box }
- Procedure TDialog.CenterText (pItem: Integer);
- Procedure TDialog.SelectText (pItem: Integer);
-
- End;
-
- Implementation
-
- Const
- Off = 0;
- On = 1;
-
- btnCtrlItem = 4;
- chkCtrlItem = 5;
- radCtrlItem = 6;
- editCtrlItem = 16;
-
- maxGroups = 15;
-
- Type
- TSearch = (searching, found, endList);
-
- HDialogInfo = ^PDialogInfo;
- PDialogInfo = ^DialogInfo;
- DialogInfo = Record
- number: Integer; {dialog resource number}
- curDialog: DialogPtr; {dialog pointer}
- numItems: DialogNumber; {number of items in dialog}
- btnDefault: Integer; {button when RETURN/ENTER hit}
- chkDefault: DialogSet; {which check boxes default on}
- textDefault: Integer; {which editText to put I-Beam}
- {$IFC UseUserItem}
- fUserItems: TUserItem; {}
- {$ENDC}
- {$IFC UseKeyGroup}
- fKeyGroups: TKeyGroup; {}
- {$ENDC}
- {$IFC UseTextGroup}
- fTextGroups: TTextGroup; {}
- {$ENDC}
- {$IFC UseRadioGroup}
- fRadioGroups: TRadioGroup; {}
- {$ENDC}
- {$IFC UsePopUpMenu}
- fPopUpMenu: TPopUpMenu; {}
- {$ENDC}
- {$IFC UseListItem}
- fListItems: TListItem; {}
- {$ENDC}
- TextBoxRgn: RgnHandle; {region of all edit text items}
- iBeamHdl: CursHandle; {handle to the special cursor}
- wasDown: Boolean; {used to obscure cursor after a click in the text}
- End;
-
- Var
- HcurInfo: HDialogInfo;
-
- globalError: Integer;
-
-
- Function DialogItemType (pItem: Integer): Integer;
- Var
- theType: Integer;
- theHandle: handle;
- theBox: Rect;
- Begin
- GetDItem(HcurInfo^^.curDialog, pItem, theType, theHandle, theBox);
- DialogItemType := theType;
- End; {DialogItemType}
-
- Procedure DialogClickButton (pItem: Integer);
- Var
- theType: Integer;
- theHandle: handle;
- theBox: Rect;
- finalTicks: Longint;
- Begin
- GetDItem(HcurInfo^^.curDialog, pItem, theType, theHandle, theBox);
- If theType = btnCtrlItem Then
- Begin
- HiliteControl(ControlHandle(theHandle), On); {make it look}
- Delay(3, finalTicks); {like the OK button was hit}
- HiliteControl(ControlHandle(theHandle), Off);
- End
- Else
- globalError := DialogInvalidItem;
- End; {DialogClickButton}
-
- Procedure DialogClickEdit (pItem: Integer);
- Begin
- If DialogItemType(pItem) = editCtrlItem Then
- SelIText(HcurInfo^^.curDialog, pItem, 0, 241)
- Else
- globalError := DialogInvalidItem;
- End; {DialogClickEdit}
-
- Procedure DialogClickRadioCheck (pItem: Integer);
- Var
- theType: Integer;
- theHandle: handle;
- theBox: Rect;
- Begin
- GetDItem(HcurInfo^^.curDialog, pItem, theType, theHandle, theBox);
- If (theType = chkCtrlItem) Or (theType = radCtrlItem) Then
- SetCtlValue(ControlHandle(theHandle), BitXor(GetCtlValue(ControlHandle(theHandle)), On))
- Else
- globalError := DialogInvalidItem;
- End; {DialogClickRadioCheck}
-
- Function DialogFilter (theDialog: DialogPtr;
- Var theEvent: EventRecord;
- Var item: Integer): Boolean;
-
- Procedure DialogNullEvent;
- Var
- mouseLoc: Point;
- Begin
- GetMouse(mouseLoc);
- If PtInRgn(mouseLoc, HcurInfo^^.TextBoxRgn) Then
- SetCursor(HcurInfo^^.iBeamHdl^^)
- Else
- SetCursor(arrow);
- End; {DialogNullEvent}
-
- Procedure DialogUpdate;
- Var
- curPen: PenState;
- theType: Integer;
- theHandle: handle;
- theBox, titleBox: Rect;
- i: Integer;
- oldPort: GrafPtr;
- Begin
- GetPort(oldPort);
- SetPort(theDialog);
- GetPenState(curPen);
- PenNormal;
- PenSize(3, 3);
- GetDItem(HcurInfo^^.curDialog, HcurInfo^^.btnDefault, theType, theHandle, theBox);
- InsetRect(theBox, -4, -4);
- FrameRoundRect(theBox, 16, 16);
- PenSize(1, 1);
- {$IFC UseRadioGroup}
- HcurInfo^^.fRadioGroups.DrawAll;
- {$ENDC}
- {$IFC UsePopUpMenu}
- HcurInfo^^.fPopUpMenu.DrawAll;
- {$ENDC}
- {$IFC UseListItem}
- HcurInfo^^.fListItems.DrawAll;
- {$ENDC}
- SetPenState(curPen);
- SetPort(oldPort);
- End; {DialogUpdate}
-
- Procedure DialogMouseDown (theEvent: EventRecord);
- Begin
- {$IFC UseUserItem}
- HcurInfo^^.fUserItems.Mouse(HcurInfo^^.curDialog, theEvent);
- {$ENDC}
- {$IFC UseListItem}
- HcurInfo^^.fListItems.Mouse(HcurInfo^^.curDialog, theEvent);
- {$ENDC}
- {$IFC UsePopUpMenu}
- HcurInfo^^.fPopUpMenu.Mouse(theEvent);
- {$ENDC}
- GlobalToLocal(theEvent.where); {because PtInRect wants it that way}
- If PtInRgn(theEvent.where, HcurInfo^^.TextBoxRgn) Then
- HcurInfo^^.wasDown := TRUE; {if mouse down in text box}
- End; {DialogMouseDown}
-
- Procedure DialogKeyDown (theEvent: EventRecord);
- Var
- i: Integer;
- chCode: Integer;
- ch: Char;
- cmdDown: Boolean;
- finalTicks: Longint;
- Begin
- With theEvent Do
- Begin
- chCode := BitAnd(message, CharCodeMask);
- ch := CHR(chCode);
- cmdDown := (BitAnd(modifiers, CmdKey) <> 0);
- End;
- If chCode In [returnCode, enterCode] Then {user pressed Return or Enter}
- Begin
- DialogClickButton(HcurInfo^^.btnDefault);
- DialogFilter := TRUE;
- item := HcurInfo^^.btnDefault;
- End
- Else If cmdDown Then
- Begin
- DialogFilter := TRUE;
- Case ch Of
- 'x':
- DlgCut(theDialog);
- 'c':
- DlgCopy(theDialog);
- 'v':
- DlgPaste(theDialog);
- 'b':
- DlgDelete(theDialog);
- Otherwise
- Begin
- {$IFC UseKeyGroup}
- i := HcurInfo^^.fKeyGroups.Click(ch);
- If i <> 0 Then
- Begin
- Case DialogItemtype(i) Of
- btnCtrlItem:
- item := i; {simulate user hitting button}
- {$IFC UseTextGroup}
- chkCtrlItem:
- HcurInfo^^.fTextGroups.Click(HcurInfo^^.curDialog, i);
- {$ELSEC}
- chkCtrlItem:
- DialogClickRadioCheck(i);
- {$ENDC}
- {$IFC UseRadioGroup}
- radCtrlItem:
- HcurInfo^^.fRadioGroups.Click(HcurInfo^^.curDialog, i);
- {$ELSEC}
- radCtrlItem:
- DialogClickRadioCheck(i);
- {$ENDC}
- editText:
- DialogClickEdit(i);
- Otherwise
- End; {case}
- End; {IF}
- {$ENDC}
- End; {Otherwise}
- End; {cmdDown}
- End; {case}
- End; {DialogKeyDown}
-
- Begin {DialogFilter}
- item := 0; {We return these two values. Initialize them.}
- DialogFilter := FALSE;
-
- If HcurInfo^^.wasDown And Not StillDown Then
- Begin
- ObscureCursor; {User clicked in editable text}
- HcurInfo^^.wasDown := FALSE; {Reset "mouse down" flag}
- End;
- Case theEvent.what Of
- nullEvent:
- DialogNullEvent;
- UpdateEvt:
- DialogUpdate;
- mouseDown:
- DialogMouseDown(theEvent);
- keyDown, autoKey:
- DialogKeyDown(theEvent);
- Otherwise
- End; {case theEvent.what}
- End; {function DialogFilter}
-
- Function DialogEvent: Integer;
- Var
- itemHit: Integer; {item where event occurred - returned by ModalDialog}
- Begin
- ModalDialog(@DialogFilter, itemHit); {calls DialogFilter for every event}
- If itemHit <> 0 Then
- Begin
- Case DialogItemType(itemHit) Of
- btnCtrlItem:
- DialogClickButton(itemHit);
- {$IFC UseTextGroup}
- chkCtrlItem:
- HcurInfo^^.fTextGroups.Click(HcurInfo^^.curDialog, itemHit);
- {$ELSEC}
- chkCtrlItem:
- DialogClickRadioCheck(itemHit);
- {$ENDC}
- {$IFC UseRadioGroup}
- radCtrlItem:
- HcurInfo^^.fRadioGroups.Click(HcurInfo^^.curDialog, itemHit);
- {$ELSEC}
- radCtrlItem:
- DialogClickRadioCheck(itemHit);
- {$ENDC}
- Otherwise
- End; {case theType}
- End; {if item <> 0}
- DialogEvent := itemHit;
- End; {DialogEvent}
-
-
- {}
- {-----------------------------------TDialog-----------------------------}
- {}
- Procedure TDialog.Init;
- Begin
- globalError := DialogNoErr;
- HcurInfo := HDialogInfo(NewHandle(SIzeOf(DialogInfo)));
- HLock(Handle(HcurInfo));
- Self.fPrivate := Handle(HcurInfo);
- HcurInfo^^.number := 0;
- HcurInfo^^.curDialog := Nil;
- HcurInfo^^.numItems := 0;
- HcurInfo^^.btnDefault := 0;
- HcurInfo^^.chkDefault := [];
- HcurInfo^^.textDefault := 0;
- HcurInfo^^.iBeamHdl := Nil;
- HcurInfo^^.wasDown := TRUE;
- {$IFC UseRadioGroup}
- new(HcurInfo^^.fRadioGroups);
- HcurInfo^^.fRadioGroups.Init;
- {$ENDC}
- {$IFC UsePopUpMenu}
- new(HcurInfo^^.fPopUpMenu);
- HcurInfo^^.fPopUpMenu.Init;
- {$ENDC}
- {$IFC UseTextGroup}
- new(HcurInfo^^.fTextGroups);
- HcurInfo^^.fTextGroups.Init;
- {$ENDC}
- {$IFC UseKeyGroup}
- new(HcurInfo^^.fKeyGroups);
- HcurInfo^^.fKeyGroups.Init;
- {$ENDC}
- {$IFC UseUserItem}
- new(HcurInfo^^.fUserItems);
- HcurInfo^^.fUserItems.Init;
- {$ENDC}
- {$IFC UseListItem}
- new(HcurInfo^^.fListItems);
- HcurInfo^^.fListItems.Init;
- {$ENDC}
- Hunlock(Handle(HcurInfo));
- End; {TDialog.Init}
-
- Procedure TDialog.Define (pNumber: Integer; {dialog number}
- pChkDefault: DialogSet; {which check boxes default on}
- pTextDefault: DialogNumber); {which editText to put I-Beam}
- Begin
- globalError := DialogNoErr;
- HcurInfo := HDialogInfo(Self.fPrivate);
- HcurInfo^^.number := pNumber;
- HcurInfo^^.chkDefault := pChkDefault;
- HcurInfo^^.textDefault := pTextDefault;
- HcurInfo^^.curDialog := GetNewDialog(HcurInfo^^.number, Nil, pointer(-1));
- End; {DialogInit}
-
- Procedure TDialog.Display (center: Boolean);
- Const
- noWrap = -1;
-
- Type
- DialogItemPtr = ^DialogItem;
- DialogItemHndl = ^DialogItemPtr;
- DialogItem = Record
- numItems: Integer; {relative to 0}
- End;
-
- Var
- theDlogPeek: DialogPeek;
- dHandle: DialogTHndl;
- iHandle: DialogItemHndl;
-
- Procedure DialogDisplayTextItems;
- Var
- i: Integer;
- theType: Integer;
- theHandle: Handle;
- theBox: Rect;
- Begin
- {Set default check boxes and get bound of all editItems}
- With HcurInfo^^ Do
- Begin
- TextBoxRgn := NewRgn;
- OpenRgn;
- For i := 1 To numItems Do
- Begin
- GetDItem(curDialog, i, theType, theHandle, theBox);
- If thetype = editCtrlItem Then
- FrameRect(theBox);
- {$IFC UseTextGroup}
- If i In chkDefault Then
- fTextGroups.Click(curDialog, i);
- {$ENDC}
- End;
- CloseRgn(TextBoxRgn);
- If textDefault <> 0 Then
- DialogClickEdit(textDefault);
- End;
- End; {DialogDisplayTextItems}
-
- Begin
- globalError := DialogNoErr;
- HcurInfo := HDialogInfo(Self.fPrivate);
- HLock(Handle(HcurInfo));
- With HcurInfo^^ Do
- Begin
- iBeamHdl := GetCursor(iBeamCursor);
- wasDown := FALSE;
- FlushEvents(everyEvent, 0);
- theDlogPeek := DialogPeek(curDialog);
- btnDefault := theDlogPeek^.aDefItem;
- iHandle := DialogItemHndl(theDlogPeek^.items);
- numItems := iHandle^^.numItems;
- theDlogPeek^.textH^^.crOnly := noWrap; {so we can turn off word wrap}
- If center Then
- Begin
- dHandle := DialogTHndl(GetResource('DLOG', number));
- Centered(dHandle^^.boundsRect, 2, 3);
- With dHandle^^.boundsRect Do
- MoveWindow(curDialog, left, top, TRUE);
- End;
-
- DialogDisplayTextItems;
- {$IFC UseRadioGroup}
- fRadioGroups.Revise(curDialog);
- {$ENDC}
- {$IFC UsePopUpMenu}
- fPopUpMenu.Revise(curDialog);
- {$ENDC}
- {$IFC UseUserItem}
- fUserItems.Revise(curDialog);
- {$ENDC}
- {$IFC UseListItem}
- fListItems.Revise(curDialog);
- {$ENDC}
- SetPort(curDialog); {this makes later GlobalToLocal calls work right}
- ShowWindow(curDialog); {here I am!}
- InitCursor; {we're ready, show an arrow}
- End; {with}
- Hunlock(Handle(HcurInfo));
- End; {TDialog.Display}
-
- Function TDialog.Accept: Integer;
- Var
- i: Integer;
- theItem: Integer;
- theType: Integer;
- theHandle: handle;
- theBox: Rect;
- Begin
- globalError := DialogNoErr;
- HcurInfo := HDialogInfo(Self.fPrivate);
- HLock(Handle(HcurInfo));
- With HcurInfo^^ Do
- Begin
- Repeat
- theItem := DialogEvent;
- Until DialogItemType(theItem) = btnCtrlItem;
- Accept := theItem;
- End; {with}
- Hunlock(Handle(HcurInfo));
- End; {DialogAccept}
-
- Function TDialog.Error: Integer;
- Begin
- Error := globalError;
- End; {TDialog.Error}
-
- Procedure TDialog.Free;
- Begin
- globalError := DialogNoErr;
- HcurInfo := HDialogInfo(Self.fPrivate);
- {$IFC UsePopUpMenu}
- HcurInfo^^.fPopUpMenu.Free;
- {$ENDC}
- {$IFC UseRadioGroup}
- HcurInfo^^.fRadioGroups.Free;
- {$ENDC}
- {$IFC UseTextGroup}
- HcurInfo^^.fTextGroups.Free;
- {$ENDC}
- {$IFC UseKeyGroup}
- HcurInfo^^.fKeyGroups.Free;
- {$ENDC}
- {$IFC UseUserItem}
- HcurInfo^^.fUserItems.Free;
- {$ENDC}
- {$IFC UseListItem}
- HcurInfo^^.fListItems.Free;
- {$ENDC}
- DisposeRgn(HcurInfo^^.TextBoxRgn);
- DisposDialog(HcurInfo^^.curDialog);
- DisposHandle(Handle(HcurInfo));
- Inherited Free;
- End; {TDialog.Destroy}
-
- Procedure TDialog.RadioGroup (pOn: DialogNumber; {which is initially on}
- pBtns: DialogSet; {which btns in a single group}
- pTitle: String; {if length > 0, then title with box}
- pTitleTop: Boolean); {TRUE - title on top, FALSE - title at left end}
- Var
- i: Integer;
- count: Integer;
- Begin
- {$IFC UseRadioGroup}
- HcurInfo := HDialogInfo(Self.fPrivate);
- HcurInfo^^.fRadioGroups.Add(pOn, pBtns, pTitle, pTitleTop);
- globalError := HcurInfo^^.fRadioGroups.Error;
- {$ELSEC}
- globalError := DialogInvalidOp;
- {$ENDC}
- End; {TDialog.RadioGroup}
-
- Procedure TDialog.RadioGroupGet (pGroup: Integer;
- Var pItem: Integer);
- Begin
- {$IFC UseRadioGroup}
- HcurInfo := HDialogInfo(Self.fPrivate);
- HcurInfo^^.fRadioGroups.Get(pGroup, pItem);
- globalError := HcurInfo^^.fRadioGroups.Error;
- {$ELSEC}
- globalError := DialogInvalidOp;
- {$ENDC}
- End; {TDialog.RadioGroupGet}
-
- Procedure TDialog.RadioGroupSet (pGroup: Integer;
- pItem: Integer);
- Begin
- {$IFC UseRadioGroup}
- HcurInfo := HDialogInfo(Self.fPrivate);
- HcurInfo^^.fRadioGroups.Click(HcurInfo^^.curDialog, pItem);
- globalError := HcurInfo^^.fRadioGroups.Error;
- {$ELSEC}
- globalError := DialogInvalidOp;
- {$ENDC}
- End; {TDialog.RadioGroupSet}
-
- Procedure TDialog.TextGroup (pItem: DialogNumber; {pairs of btn and edit text items}
- pText: DialogNumber);
- Begin
- {$IFC UseTextGroup}
- HcurInfo := HDialogInfo(Self.fPrivate);
- HcurInfo^^.fTextGroups.Add(pItem, pText);
- globalError := HcurInfo^^.fTextGroups.Error;
- {$ELSEC}
- globalError := DialogInvalidOp;
- {$ENDC}
- End; {DialogTextGroup}
-
- Procedure TDialog.PopMenu (pMenu: MenuHandle; {}
- pMenuRes: Integer; {}
- pStatic: DialogNumber; {}
- pInitiallyOn: Integer); {}
- Begin
- {$IFC UsePopUpMenu}
- HcurInfo := HDialogInfo(Self.fPrivate);
- HcurInfo^^.fPopUpMenu.Add(pMenu, pMenuRes, pStatic, pInitiallyOn);
- globalError := HcurInfo^^.fPopUpMenu.Error;
- {$ELSEC}
- globalError := DialogInvalidOp;
- {$ENDC}
- End; {TDialog.PopMenu}
-
- Procedure TDialog.PopMenuGet (pGroup: Integer;
- Var pItem: Integer;
- Var pText: Str255);
- Begin
- {$IFC UsePopUpMenu}
- HcurInfo := HDialogInfo(Self.fPrivate);
- HcurInfo^^.fPopUpMenu.Get(pGroup, pItem, pText);
- globalError := HcurInfo^^.fPopUpMenu.Error;
- {$ELSEC}
- globalError := DialogInvalidOp;
- {$ENDC}
- End; {TDialog.PopMenuGet}
-
- Procedure TDialog.PopMenuCallBack (pCallBack: ProcPtr); {proc addr}
- Begin
- {$IFC UsePopUpMenu}
- HcurInfo := HDialogInfo(Self.fPrivate);
- HcurInfo^^.fPopUpMenu.CallBack(pCallBack);
- globalError := HcurInfo^^.fPopUpMenu.Error;
- {$ELSEC}
- globalError := DialogInvalidOp;
- {$ENDC}
- End; {TDialog.PopMenuCallBack}
-
- Procedure TDialog.UserItems (pItem: DialogNumber; {user item number}
- pDraw, pEvent, pSelect: ProcPtr; {}
- pBox: Rect); {Rect that contains the item}
- Begin
- {$IFC UseUserItem}
- HcurInfo := HDialogInfo(Self.fPrivate);
- HcurInfo^^.fUserItems.Add(pItem, pDraw, pEvent, pSelect, pBox);
- globalError := HcurInfo^^.fUserItems.Error;
- {$ELSEC}
- globalError := DialogInvalidOp;
- {$ENDC}
- End; {TDialog.UserItem}
-
- Procedure TDialog.ItemList (pItem: DialogNumber; {item number}
- pInitiallyOn: Integer; {item initially selected}
- pShown: Integer); {max items to show}
- Begin
- {$IFC UseListItem}
- HcurInfo := HDialogInfo(Self.fPrivate);
- HcurInfo^^.fListItems.Add(pItem, pInitiallyOn, pShown);
- globalError := HcurInfo^^.fListItems.Error;
- {$ELSEC}
- globalError := DialogInvalidOp;
- {$ENDC}
- End; {TDialog.ItemList}
-
- Procedure TDialog.ItemListText (pText: Str255);
- Begin
- {$IFC UseListItem}
- HcurInfo := HDialogInfo(Self.fPrivate);
- HcurInfo^^.fListItems.AddItem(pText);
- globalError := HcurInfo^^.fListItems.Error;
- {$ELSEC}
- globalError := DialogInvalidOp;
- {$ENDC}
- End; {TDialog.ItemListText}
-
- Procedure TDialog.ItemListGet (pGroup: Integer;
- Var pItem: Integer;
- Var pText: Str255);
- Begin
- {$IFC UseListItem}
- HcurInfo := HDialogInfo(Self.fPrivate);
- HcurInfo^^.fListItems.Get(pGroup, pItem, pText);
- globalError := HcurInfo^^.fListItems.Error;
- {$ELSEC}
- globalError := DialogInvalidOp;
- {$ENDC}
- End; {TDialog.ItemListGet}
-
- Procedure TDialog.KeyButton (pKey: Char; {command key}
- pItem: DialogNumber); {button}
- Begin
- {$IFC UseKeyGroup}
- HcurInfo := HDialogInfo(Self.fPrivate);
- HcurInfo^^.fKeyGroups.Add(pKey, pItem);
- globalError := HcurInfo^^.fKeyGroups.Error;
- {$ELSEC}
- globalError := DialogInvalidOp;
- {$ENDC}
- End; {TDialog.KeyButton}
-
- Function TDialog.GetBooleanValue (pItem: Integer): Boolean;
- Var
- theType: Integer;
- theHandle: handle;
- theBox: Rect;
- Begin
- globalError := DialogNoErr;
- HcurInfo := HDialogInfo(Self.fPrivate);
- GetDitem(HcurInfo^^.curDialog, pItem, theType, theHandle, theBox);
- If (theType = radCtrlItem) Or (theType = chkCtrlItem) Then
- GetBooleanValue := (GetCtlValue(ControlHandle(theHandle)) = On)
- Else
- Begin
- globalError := DialogInvalidItem;
- GetBooleanValue := FALSE;
- End;
- End; {TDialog.GetBooleanValue}
-
- Function TDialog.GetLongintValue (pItem: Integer): Longint;
- Var
- theType: Integer;
- theHandle: handle;
- theBox: Rect;
- theText: Str255;
- theValue: Longint;
- isNum: Boolean;
- i: Integer;
- c: Char;
- Begin
- globalError := DialogNoErr;
- HcurInfo := HDialogInfo(Self.fPrivate);
- GetDItem(HcurInfo^^.curDialog, pItem, theType, theHandle, theBox);
- If (theType = editText) Or (theType = statText) Then
- Begin
- GetIText(theHandle, theText);
- For i := 1 To Length(theText) Do
- Begin
- c := Copy(theText, i, 1);
- If i = 1 Then
- isNum := c In ['+', '-', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
- Else
- isNum := isNum And (c In ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']);
- End;
- If isNum Then
- StringToNum(theText, theValue)
- Else
- Begin
- globalError := DialogNotNumber;
- theValue := 0;
- End;
- End {if Edit/Static Text item}
- Else
- Begin
- globalError := DialogNotNumber;
- theValue := 0;
- End;
- GetLongintValue := theValue;
- End; {TDialog.GetLongintValue}
-
- Function TDialog.GetStringValue (pItem: Integer): Str255;
- Var
- theType: Integer;
- theHandle: handle;
- theBox: Rect;
- theText: Str255;
- Begin
- globalError := DialogNoErr;
- HcurInfo := HDialogInfo(Self.fPrivate);
- GetDItem(HcurInfo^^.curDialog, pItem, theType, theHandle, theBox);
- If (theType = editText) Or (theType = statText) Then
- Begin
- GetIText(theHandle, theText);
- GetStringValue := theText;
- End
- Else
- Begin
- globalError := DialogInvalidItem;
- GetStringValue := '';
- End;
- End; {TDialog.GetStringValue}
-
- Procedure TDialog.SetBooleanValue (pItem: Integer;
- theValue: Boolean);
- Var
- theType: Integer;
- theHandle: handle;
- theBox: Rect;
- Begin
- globalError := DialogNoErr;
- HcurInfo := HDialogInfo(Self.fPrivate);
- GetDItem(HcurInfo^^.curDialog, pItem, theType, theHandle, theBox);
- If (theType = radCtrlItem) Or (theType = chkCtrlItem) Then
- If theValue Then
- SetCtlValue(ControlHandle(theHandle), On)
- Else
- SetCtlValue(ControlHandle(theHandle), Off)
- Else
- globalError := DialogInvalidItem;
- End; {TDialog.SetBooleanValue}
-
- Procedure TDialog.SetLongintValue (pItem: Integer;
- theValue: Longint);
- Var
- theType: Integer;
- theHandle: handle;
- theBox: Rect;
- theText: Str255;
- Begin
- globalError := DialogNoErr;
- HcurInfo := HDialogInfo(Self.fPrivate);
- GetDItem(HcurInfo^^.curDialog, pItem, theType, theHandle, theBox);
- If (theType = editText) Or (theType = statText) Then
- Begin
- NumToString(theValue, theText);
- SetIText(theHandle, theText);
- End
- Else
- globalError := DialogInvalidItem;
- End; {TDialog.SetLongintValue}
-
- Procedure TDialog.SetStringValue (pItem: Integer;
- theValue: Str255;
- forceFit: Boolean);
- Var
- theType: Integer;
- theHandle: handle;
- theBox: Rect;
- width, middle: Integer;
- firstHalf, secondHalf: Str255;
- Begin
- globalError := DialogNoErr;
- HcurInfo := HDialogInfo(Self.fPrivate);
- GetDItem(HcurInfo^^.curDialog, pItem, theType, theHandle, theBox);
- If forceFit Then
- Begin
- width := thebox.right - theBox.left;
- If (StringWidth(theValue) > width) Then
- Begin
- middle := Length(theValue) Div 2;
- firstHalf := Copy(theValue, 1, middle);
- secondHalf := Copy(theValue, middle + 1, 255);
- Repeat
- firstHalf := Copy(firstHalf, 1, Length(firstHalf) - 1);
- secondHalf := Copy(secondHalf, 2, Length(secondHalf) - 1);
- theValue := Concat(firstHalf, '╔', secondHalf);
- Until (StringWidth(theValue) < width);
- End;
- End; {if forceFit}
- If (theType = editText) Or (theType = statText) Then
- SetIText(theHandle, theValue)
- Else
- globalError := DialogInvalidItem;
- End; {TDialog.SetStringValue}
-
- Procedure TDialog.SelectText (pItem: Integer);
- Begin
- globalError := DialogNoErr;
- HcurInfo := HDialogInfo(Self.fPrivate);
- DialogClickEdit(pItem);
- End; {TDialog.SelectText}
-
- Procedure TDialog.CenterText (pItem: Integer);
- Var
- iText: Str255;
- nilText: Str255;
- theBox: Rect;
- theType: Integer;
- theHandle: Handle;
- Begin
- globalError := DialogNoErr;
- HcurInfo := HDialogInfo(Self.fPrivate);
- GetDItem(HcurInfo^^.curDialog, pItem, theType, theHandle, theBox);
- If (theType = editText) Or (theType = statText) Then
- Begin
- nilText := '';
- GetIText(theHandle, iText);
- SetIText(theHandle, nilText);
- TextBox(Ptr(Ord(@iText) + 1), Length(iText), theBox, teJustCenter);
- End
- Else
- globalError := DialogInvalidItem;
- End; {TDialog.CenterText}
-
- End.